{extend name="../../public/admin"}
{block name="title"}咨询列表{/block}
{block name="css"}{/block}
{block name="body"}

<div id="container">

    <div class="clearfix"></div>
    <div style="height: 20px;"></div>
    <div class="table-responsive">
        <table class="table table-bordered table-hover table-input" v-cloak>
            <thead>
            <tr class="active">
                <th colspan="5">
                   <span class="fa-pull-right">总 <strong>{{list.length}}</strong> 条</span>
                </th>
            </tr>

            <tr class="active">
                <th>编号</th>
                <th>时间</th>
                <th>名称</th>
                <th class="text-center">操作</th>
            </tr>
            </thead>
            <tbody>
            <template v-for="(key,index) in list">
                <tr>
                    <td>{{key.id}}</td>
                    <td><input type="text" v-model="key.name" @change="up(index)"></td>
                    <td>{{key.add_time}}</td>
                    <td class="text-center">
                        <a href="javascript:;" class="btn btn-xs" title="删除" @click="de(index)"><i class="fa fa-trash-o"></i></a>
                    </td>
                </tr>
            </template>
            </tbody>
        </table>
        <div id="Pagination"></div>
    </div>
</div>
{/block}
{block name="js"}

<script>
    (()=>{
        const app = new Vue({
            el:'#container',
            data:{
                list:[]
            }
        });

        //初始数据
        get_data(function (da) {
            get_data(function (da) {
                app.list = da;
            });
        });

        //删除内容
        app.de = (i)=>{
            layer.confirm('确定要删除',function () {
                layer.closeAll();
                $.get(DJOURNALISM+'/type/id/'+app.list[i].id,function (da) {
                    if (da == 1) {
                        layer.msg('删除成功',{icon:1,offset:'rb'});
                    } else{
                        layer.msg('删除失败',{icon:2,offset:'rb',end:function () {
                                location.reload();
                            }});

                    }
                });
                app.list.splice(i,1);
            });

        };

        //修改咨询
        app.up = (i)=>{
            $.get(DJOURNALISM+'/type',{id:app.list[i].id,up:app.list[i].name},function (da) {
                if (da == 1) {
                    layer.msg('修改成功',{icon:1,offset:'rb'});
                }
                else{
                    layer.msg('修改失败',{icon:2,offset:'rb',end:function () {
                            location.reload();
                        }});
                }
            })
        };
        //发送数据
        function get_data(fn = 1) {
            layer.load(2);
            $.post(DJOURNALISM+'/zi_xun',function (da) {
                layer.closeAll();
                fn(da);
            })
        }
    })();
</script>
{/block}